package com.example.webfluxdemo.domain;

import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveSortingRepository;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.util.List;

public interface AdSpaceRepository extends ReactiveSortingRepository<AdSpaceEntity, Integer> {
    @Query("select * from AdSpaceEntity")
    Flux<AdSpaceEntity> findAll();
    Flux<AdSpaceEntity> findByStatus(Integer status);
    @Query("select a.* from ad_space a inner join ad_space_platform_config b on a.id=b.ad_space_id where identity_id=:identity")
    Mono<AdSpaceEntity> findByIdentityId(String identity);
    Mono<AdSpaceEntity> getById(int id);
    Flux<AdSpaceEntity> findByLastChangedTimeGreaterThan(LocalDateTime date);

    @Query("select distinct a.identity_id from ad_space a" +
            " inner join ad_space_platform_config b on a.id=b.ad_space_id" +
            " where b.status=1 and b.main_id in (:mainConfigIds)")
    Flux<String> findByMainConfigIds(List<Integer> mainConfigIds);
}
